﻿<Page
    x:Name="pageRoot"
    x:Class="ReferenceTemplate.Windows8.MainPage"
    DataContext="{Binding Source={StaticResource Locator}, Path=Main}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ReferenceTemplate.Windows8"
    xmlns:common="using:ReferenceTemplate.Windows8.Common"
    xmlns:converter="using:ReferenceTemplate.Windows8.Converter"
    xmlns:controls="using:ReferenceTemplate.Windows8.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Resources>
        <!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
        <x:String x:Key="AppName">New forms of Code</x:String>
        <converter:ConvertImagePath x:Key="ConvertImagePath"/>
        <converter:ParallaxConverter x:Key="ParallaxConverter"/>
        <DataTemplate x:Key="LinkItemTemplate">
        	<Grid Height="150" Width="500">
                <Border BorderBrush="Black" BorderThickness="0,0,1,0" Background="{Binding Main.Color, Source={StaticResource Locator}}" HorizontalAlignment="Right" Height="17" VerticalAlignment="Bottom" Width="100" Margin="0,0,10.5,60" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
        			<Border.RenderTransform>
        				<CompositeTransform SkewX="51"/>
        			</Border.RenderTransform>
        		</Border>
                <Border BorderBrush="Black" BorderThickness="1,0,0,0" Background="{Binding Main.Color, Source={StaticResource Locator}}" HorizontalAlignment="Left" Height="17" VerticalAlignment="Bottom" Width="100" Margin="10.5,0,0,60" RenderTransformOrigin="0.5,0.5" UseLayoutRounding="False" d:LayoutRounding="Auto">
                	<Border.RenderTransform>
                		<CompositeTransform SkewX="-51"/>
                	</Border.RenderTransform>
                </Border>
        		<Grid Margin="10,0">
        			<Grid.Background>
        				<ImageBrush Stretch="UniformToFill" ImageSource="{Binding Image, Converter={StaticResource ConvertImagePath}}"/>
        			</Grid.Background>
        			<Rectangle Fill="{Binding Image, Converter={StaticResource ConvertImagePath}}" Stroke="Black" StrokeThickness="2"/>
        		</Grid>
        		<Grid Margin="0" Background="{Binding Main.Color, Source={StaticResource Locator}}" Height="60" VerticalAlignment="Bottom" RenderTransformOrigin="0.5,0.5">
        			<Rectangle Stroke="Black" StrokeThickness="1"/>
        			<TextBlock HorizontalAlignment="Left" Text="{Binding Title}" VerticalAlignment="Center" FontSize="24" TextTrimming="WordEllipsis" Margin="10"/>
        		</Grid>
        	</Grid>
        </DataTemplate>
    </Page.Resources>

    <!--
        This grid acts as a root panel for the page that defines two rows:
        * Row 0 contains the back button and page title
        * Row 1 contains the rest of the page layout
    -->
    <Grid>
        
        <Grid.ChildrenTransitions>
            <TransitionCollection>
                <EntranceThemeTransition/>
            </TransitionCollection>
        </Grid.ChildrenTransitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!-- Back button and page title -->
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="120"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                        Style="{StaticResource NavigationBackButtonNormalStyle}"
                        VerticalAlignment="Top"
                        AutomationProperties.Name="Back"
                        AutomationProperties.AutomationId="BackButton"
                        AutomationProperties.ItemType="Navigation Button"/>
            <TextBlock x:Name="pageTitle" Text="{Binding AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                        IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
        </Grid>
        <controls:OffsetGridView x:Name="Links" Grid.Row="1" Padding="140,0,140,10" SelectedItem="{Binding SelectedLink, Mode=TwoWay}" ItemsSource="{Binding Links}" ItemTemplate="{StaticResource LinkItemTemplate}" SelectionMode="None" IsItemClickEnabled="True" ItemClick="GridView_ItemClick">
            <controls:OffsetGridView.ItemContainerStyle>
                <Style TargetType="FrameworkElement">
                    <Setter Property="Margin" Value="0,0,80,0"/>
                </Style>
            </controls:OffsetGridView.ItemContainerStyle>
        </controls:OffsetGridView>

        <Grid.Background>
            <ImageBrush Stretch="UniformToFill" ImageSource="{Binding Background, Converter={StaticResource ConvertImagePath}}">
                <ImageBrush.Transform>
                    <CompositeTransform ScaleX="1.2" ScaleY="1.2" TranslateX="{Binding ElementName=Links, Path=Offset, Converter={StaticResource ParallaxConverter}}"/>
                </ImageBrush.Transform>
            </ImageBrush>
        </Grid.Background>
    </Grid>
</Page>
